// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import Mint from 'mint-ui';
import 'mint-ui/lib/style.css';    // 默认主题

import axios from 'axios';
import moment from 'moment';

import "babel-polyfill";

import global from './components/common/Global.js';


// http response 拦截器
axios.interceptors.response.use(
    response => {
        return response;
    },
    error => {
        return Promise.reject(error.response.data)   // 返回接口返回的错误信息
    });

Vue.use(Mint);
Vue.prototype.$axios = axios;
Vue.prototype.$moment = moment;
Vue.prototype.$global = global;

Vue.config.productionTip = false

Vue.prototype.$mPost = function(paramObj,okCallback,errorCallback = null,catchCallback=null){
    var rq_data = JSON.parse(localStorage.getItem('rq_data'));

    this.$axios.post(this.$global.API_URL,{
        "apiName":paramObj.apiName,
        "param":paramObj.param
    },{
        headers:{'stoken':rq_data.stoken,'sid':rq_data.sid}
    }).then((res) => {
        if(res.data.code == 200 || res.data.result == 200){
            okCallback ? okCallback.call(null, res) : function(){}
        }else{
            errorCallback ? errorCallback.call(null,res) : this.$router.push('/login');
        }

    }).catch((ret)=>{
        // catchCallback ? catchCallback.call(null, ret) :  this.$router.push('/login');
        catchCallback ? catchCallback.call(null, ret) :  function(){};
    });

}


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
